package cool.taomu.toolkit.rpc

import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.ToString

class RpcContext {
	static val ThreadLocal<ClientInfo> CLIENT_INFO_THREAD_LOCAL = new ThreadLocal();

	def static void setClientInfo(String host, int port) {
		CLIENT_INFO_THREAD_LOCAL.set(new ClientInfo(host, port));
	}

	def static ClientInfo getClientInfo() {
		return CLIENT_INFO_THREAD_LOCAL.get();
	}

	def static void clear() {
		CLIENT_INFO_THREAD_LOCAL.remove();
	}

	@Accessors
	@ToString
	static class ClientInfo {
		val String host;
		val int port;

		new(String host, int port) {
			this.host = host;
			this.port = port;
		}
	}
}
